var config = require('../../config.js')
var http = require('../../utils/httpHelper.js')
Page({
  data:{
    userInfo:{},
    datingList:[],
    timer:{},
    datingPage:{
      current:1,
      pageSize:10,
			total:0
    },
  },
  onLoad: function () {
    var that = this;
    let userInfo = wx.getStorageSync('user');
    that.setData({
      userInfo:userInfo
    });
  },
  onShow:function(){
    var that = this;
    this.getlist(function(list){
      that.setData({datingList:list});
    });
  },
  onReachBottom(){
    if(this.timer != null){
      clearTimeout(this.timer)
    }
    this.timer = setTimeout(()=>{
      this.getMoreData();
    },1000)
  },
  getMoreData() {
    var that = this;
    that.data.datingPage.current++;
    that.getlist(function(list){
      let yList = that.data.datingList;
      yList = yList.concat(list);
      that.setData({datingList:yList});
    })
  },
  getlist:function(callback){
    var that = this;
    http.httpPost(config.clubApi.getDatingList,{
      pageNo:that.data.datingPage.current,
      pageSize:that.data.datingPage.pageSize,
      createBy:that.data.userInfo.userId,
      productType:0
    },function(res){
      if(res.code == '200'){
        var list = res.data.pageData;
        typeof callback == "function" && callback(list)
      }
    });
  },
  cancelDating:function (e){    
    var that = this;
    http.httpPut(config.clubApi.delDating,{
      id:e.target.id
    },function(res){
      if(res.code == '200'){
        wx.showToast({
          title: '取消预约成功!',
          icon: 'success',
          duration: 1000
        })
        that.getlist(function(list){
          that.setData({datingList:list});
        });
      }
    });
  }  
})